﻿//https://leetcode.cn/problems/sliding-window-maximum/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k)
    {
        vector<int> ret;
        int n = nums.size();
        priority_queue<pair<int, int>> pq;
        for (int i = 0; i < k; i++)
        {
            pq.emplace(nums[i], i);
        }
        ret.push_back(pq.top().first);
        for (int i = k; i < n; i++)
        {
            pq.emplace(nums[i], i);
            while (pq.top().second <= i - k)
            {
                pq.pop();
            }

            ret.push_back(pq.top().first);
        }
        return ret;

    }
};